/**
 * Created by GadflyBSD on 16/3/12.
 */
var meta = new Object();
var content = document.getElementsByTagName('meta');
var templatePath = '/Public/template/Manage/';
for(var i=0;i<content.length;i++){
	if(content[i].getAttribute('name') == 'login')
		meta.login = content[i].getAttribute('content');
	if(content[i].getAttribute('name') == 'logout')
		meta.logout = content[i].getAttribute('content');
	if(content[i].getAttribute('name') == 'register')
		meta.register = content[i].getAttribute('content');
	if(content[i].getAttribute('name') == 'Authcode')
		meta.appurl = content[i].getAttribute('content');
	if(content[i].getAttribute('name') == 'appurl')
		meta.verifyImg = content[i].getAttribute('content');
	if(content[i].getAttribute('name') == 'verifySms')
		meta.verifySms = content[i].getAttribute('content');
	if(content[i].getAttribute('name') == 'upload')
		meta.upload = content[i].getAttribute('content');
	if(content[i].getAttribute('name') == 'load')
		meta.load = content[i].getAttribute('content');
	if(content[i].getAttribute('name') == 'ajax')
		meta.ajax = content[i].getAttribute('content');
	if(content[i].getAttribute('name') == 'angular')
		meta.angular = content[i].getAttribute('content');
}
var myApp = angular.module('myApp', ['ngRoute', 'myApp.index', 'myApp.shop', 'myApp.money', 'myApp.person', 'myApp.user', 'myApp.recharge', 'myApp.setting', 'ui.bootstrap', 'dialogs.main', 'pascalprecht.translate','dialogs.default-translations']);
myApp.config(['$routeProvider', 'dialogsProvider','$translateProvider', function($routeProvider, dialogsProvider, $translateProvider) {
	$routeProvider.when('/index', {
		templateUrl: templatePath + 'index.html',
		controller: 'indexCtrl'
	}).
	when('/shop', {
		templateUrl: templatePath + 'shop.html',
		controller: 'shopCtrl'
	}).
	when('/money', {
		templateUrl: templatePath + 'money.html',
		controller: 'moneyCtrl'
	}).
	when('/person', {
		templateUrl: templatePath + 'person.html',
		controller: 'personCtrl'
	}).
	when('/user', {
		templateUrl: templatePath + 'user.html',
		controller: 'userCtrl'
	}).
	when('/recharge', {
		templateUrl: templatePath + 'recharge.html',
		controller: 'rechargeCtrl'
	}).
	when('/setting', {
		templateUrl: templatePath + 'setting.html',
		controller: 'settingCtrl'
	}).otherwise({redirectTo: '/index'});
	dialogsProvider.useBackdrop('static');
	dialogsProvider.useEscClose(false);
	dialogsProvider.useCopy(false);
	dialogsProvider.setSize('sm');
	dialogsProvider.useFontAwesome();
	$translateProvider.preferredLanguage('zh-CN');
}]).
factory('shopService', ['$http', function($http){
	return {
		getShopList: function(page){
			return $http.post(meta.angular, {ac: 'angular', op: 'getShopList', page: (typeof page == 'undefined')?1:page});
		},
		getSurveyList: function(page){
			return $http.post(meta.angular, {ac: 'angular', op: 'getSurveyList', page: (typeof page == 'undefined')?1:page});
		},
		getShopInfo: function(sid){
			return $http.post(meta.angular, {ac: 'angular', op: 'getShopInfo', sid: sid});
		},
		setVipLimit: function(param){
			param.ac = 'angular';
			param.op = 'setVipLimit';
			return $http.post(meta.angular, param);
		},
		saveSettingInfo: function(param){
			param.ac = 'angular';
			param.op = 'saveSettingInfo';
			return $http.post(meta.angular, param);
		},
		checkWithdraw: function(sid){
			return $http.post(meta.angular, {ac: 'angular', op: 'checkWithdraw', sid: sid});
		},
		checkWithdrawAll: function(){
			return $http.post(meta.angular,  {ac: 'angular', op: 'checkWithdraw'});
		},
		withdraw: function(sid){
			return $http.post(meta.angular, {ac: 'angular', op: 'withdraw', sid: sid});
		},
		withdrawAll: function(){
			return $http.post(meta.angular,  {ac: 'angular', op: 'withdrawAll'});
		},
		getSettleList: function(start, end){
			return $http.post(meta.angular, {ac: 'angular', op: 'getSettleList', start: start, end: end});
		},
		removeSurveyBind: function(bid){
			return $http.post(meta.angular, {ac: 'angular', op: 'removeSurveyBind', bid: bid});
		},
		sendSms: function(mobile){
			return ajax({op: 'sendSms', mobile: mobile, action: action});
		},
		test: function(){
			"use strict";
			return $http.post('/Public/json/test.json');
		}
	};
}]);